package com.monkeygroup.mygoplus.ecchat.ui.contact.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Administrator on 2016/9/9.
 */
public class MGDbHelper extends SQLiteOpenHelper {
    private static final String MYGOSEARCH_DB_NAME = "mygosearch.db";
    private static MGDbHelper instance;
    private static final int DATABASE_VERSION = 1;


    private MGDbHelper(Context context) {
        super(context, MYGOSEARCH_DB_NAME, null, DATABASE_VERSION);
    }

    public static MGDbHelper getInstance(Context context) {
        if (instance == null) {
            instance = new MGDbHelper(context);
        }

        return instance;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(ContactRecord.CONTACT_TABLE_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        System.out.println("oldVersion:newVersion=" + oldVersion + " : " + newVersion);

    }

    public void closeDB() {
        if (instance != null) {
            try {
                SQLiteDatabase db = instance.getWritableDatabase();
                db.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            instance = null;
        }
    }

}
